package com.hcl.orm.sample.dao;

import com.hcl.orm.core.annotation.DBType;
import com.hcl.orm.core.annotation.DataAccess;
import com.hcl.orm.core.annotation.Script;
import com.hcl.orm.core.executor.page.PageParam;
import com.hcl.orm.core.executor.page.PageResult;
import com.hcl.orm.sample.domain.Businentrust;

import java.util.List;

/**
 * @author hucl
 * @projectName jim-orm
 * @description: TODO
 * @date 2021/5/2513:20
 */
@DataAccess
public interface BusinentrustDAO {

    /**
     * 根据allotNo获取订单
     *
     * @param allotNo
     * @return
     */
    @Script(value = "SELECT * from prd_busin_entrust"
            + " where 1=1 [AND allot_no = #{??allotNo}]")
    Businentrust getBusinEntrustByAllotNo(String allotNo);


    /**
     * 可撤委托查询
     *
     * @param pageParam
     * @param fundAccount
     * @param allotNo
     * @param prodtaNo
     * @param prodCode
     * @return
     */
    @Script("select a.init_date, a.entrust_no, a.curr_date, a.curr_milltime, a.op_station , "
            + "a.op_branch_no, a.operator_no, a.op_entrust_way, a.prod_entrustsrc_type, a.allot_no , a.batch_no, "
            + "a.original_appno, a.fund_account, a.client_id, a.prod_account , a.trans_account, a.pay_account, a.pay_kind, "
            + "a.bank_no, a.oppo_prodaccount , a.other_transaccount, a.developer, a.ta_type, a.prodta_no, a.prod_code , "
            + "a.prod_name, a.trade_report_type, a.money_type, a.dividend_way, a.charge_type , a.prodcode_type, "
            + "a.prod_type_ass, a.discount_rate, a.switch_prod_code, a.switch_charge_type , a.entrust_balance, "
            + "a.entrust_price, a.otc_entrust_status, a.invpay_status , a.prod_revisit_status, "
            + "a.verify_status, a.settle_date, a.business_balance, a.business_date, a.ta_serialno, "
            + "a.error_info, a.error_code, a.prodrisk_level , a.corp_risk_level, a.ta_risk_level, a.risk_enddate, "
            + "a.prodrisk_flag, a.elig_check_str , a.cancel_serial_no, a.elig_confirm_type, a.agreement_id_str, a.prod_prop, "
            + "a.redeem_type , a.register_date, a.agency_no, a.other_agency, a.ratio_sx, a.sale_fare , a.other_fare, "
            + "a.exceed_flag, a.notrade_kind, a.id_kind, a.id_no , a.organ_flag, a.net_no, a.other_netno, a.otc_deal_flag, "
            + "a.valid_date, a.date_clear, a.remark, a.position_str, a.report_no, a.report_date , a.prodcode_sub_type"
            + " from prd_busin_entrust a where a.fund_account = #{fundAccount} "
            + "[and a.allot_no = #{??allotNo} ]"
            + "[and a.prodta_no = #{??prodtaNo} ]"
            + "[and a.prod_code = #{??prodCode} ]" + "and (a.otc_entrust_status in ('2')) "
            + "and (a.invpay_status in (' ','0','2'))")
    PageResult<Businentrust> getBusinentrustWithdraw(PageParam pageParam, String fundAccount, String allotNo, String prodtaNo,
                                                     String prodCode);

    /**
     * 根据交易日期获取记录
     *
     * @param initDate
     * @return
     */
    @Script(value = "select * from prd_busin_entrust where init_date = #{initDate}")
    List<Businentrust> getBusinentrustRecord(Integer initDate);

    /**
     * 获取资金账号
     * @return
     */
    @Script(value = "select fund_account from (select hs_rownum() as rec_count, fund_account  \n" +
            "from (select distinct fund_account from prd_busin_entrust order by fund_account)) f\n" +
            " where mod(f.rec_count, 1) = 0;")
    List<String> getFundAccountList();
}
